package com.rayc.helloworld;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rayc.config.RabbitmMQClient;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Publisher {
    @Test
    public void publish() throws Exception {
        //1.获取Connection
        Connection connection = RabbitmMQClient.getConnection();
        //2.创建Channel
        Channel channel = connection.createChannel();
        //3.发布消息到exchange,同时指定路由规则
        String msg = "Hello-World";
        channel.basicPublish("", "HelloWorld", null, msg.getBytes());
        System.out.println("生成者开始发布消息");
        //4.释放资源
        channel.close();
        connection.close();
    }
}
